#ifndef TC_TRACEMGR_HH
#define TC_TRACEMGR_HH

/** \file TraceMgr.hh 
 * Declarations for Trace Manager class
 *
 * (c) Copyright  Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Log.hh,v 1.3 2008/10/09 04:51:41 bdssadm Exp $
 *
 *
 */

// Standard headers
#include <vector>
#include <iosfwd>
// Project headers
#include "Global.hh"
#include "Trace.hh"

namespace TC {

// FORWARDS
struct CodeContext;

class TraceMgr {
  
 public:

  // TYPES
  typedef std::vector<const CodeContext*> Stack_t;

  // CREATORS
  TraceMgr();
  ~TraceMgr();

  // ACCESSORS
  //! Print current stack trace to debug stream
  void printStack() const;
  
  // MODIFIERS
  //! Clear current stack trace
  void clearStack()
  { m_stack.clear(); }
  //! A trace scope (object) enters (instantiated)
  void traceEnter(const Trace* t)
  { m_stack.push_back(t->m_ctx); }
    //! A trace scope (object) exits (destroyed)
  void traceExit(const Trace*)
  { !m_stack.empty() ? m_stack.pop_back() : (void)0 ; }

  // STATIC FUNCTIONS
  static TraceMgr& GetInstance();

 private:
  // NOT ALLOWED
  TraceMgr(const TraceMgr&);
  void operator=(const TraceMgr&);

  // MEMBERS
  //! Call stack of trace objects
  Stack_t m_stack;

};  

//! Stream inserter for CodeContext object
std::ostream& operator<<(std::ostream& os, const CodeContext& ctx);

} // end namespace


#endif /* Include guard */
